﻿using System;
using DependencyAnalysis.DataModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using theeg.DependencyAnalysis.CommonAddin.Converters;

namespace UnitTests.Addin
{
    [TestClass]
    public class HiddenNodeToNameConverterTest
    {
        private HiddenNodeToNameConverter _converter;

        [TestInitialize]
        public void Initialize()
        {
            _converter = new HiddenNodeToNameConverter();
        }

        [TestMethod]
        public void WhenNullThenReturnEmptyString()
        {
            var result = _converter.Convert(null, null, null, null);
            Assert.AreEqual(string.Empty, result);
        }

        [TestMethod]
        public void WhenNoSupportedTypeThenReturnEmptyString()
        {
            var result = _converter.Convert(5, null, null, null);
            Assert.AreEqual(string.Empty, result);
        }

        [TestMethod]
        public void WhenModuleThenReturnFullName()
        {
            var module = new ModuleDescriptor { FullName = "Hoshi.Bob" };
            var result = _converter.Convert(module, null, null, null);
            Assert.AreEqual("Module: Hoshi.Bob", result);
        }

        [TestMethod]
        public void WhenSubmoduleAndHasModuleThenReturnFullNameInModule()
        {
            var module = new ModuleDescriptor { FullName = "Hoshi.Bob" };
            var submodule = new SubmoduleDescriptor { FullName = "Hoshi.Bob.Sub", Name = "Supi", Module = module };
            var result = _converter.Convert(submodule, null, null, null);
            Assert.AreEqual("Submodule: Hoshi.Bob.Sub in Hoshi.Bob", result);
        }

        [TestMethod]
        public void WhenSubmoduleWithoutFullNameThenReturnDotInModule()
        {
            var module = new ModuleDescriptor { FullName = "Hoshi.Bob" };
            var submodule = new SubmoduleDescriptor { FullName = "", Name = "Supi", Module = module };
            var result = _converter.Convert(submodule, null, null, null);
            Assert.AreEqual("Submodule: . in Hoshi.Bob", result);
        }

        [TestMethod]
        public void WhenSubmoduleWithoutModuleThenReturnFullName()
        {
            var submodule = new SubmoduleDescriptor { FullName = "Hoshi.Bob.Sub", Name = "Supi" };
            var result = _converter.Convert(submodule, null, null, null);
            Assert.AreEqual("Submodule: Hoshi.Bob.Sub", result);
        }

        [TestMethod]
        public void WhenTypeThenReturnFullName()
        {
            var type = new TypeDescriptor { FullName = "Hoshi.Bob.Type" };
            var result = _converter.Convert(type, null, null, null);
            Assert.AreEqual("Type: Hoshi.Bob.Type", result);
        }

        [TestMethod]
        public void WhenMemberThenReturnFullName()
        {
            var member = new MemberDescriptor { FullName = "Hoshi.Bob.Type.§Void Flush()" };
            var result = _converter.Convert(member, null, null, null);
            Assert.AreEqual("Member: Hoshi.Bob.Type.§Void Flush()", result);
        }
        
        [TestMethod]
        public void ConvertBackIsNotImplemented()
        {
            try
            {
                _converter.ConvertBack(null, null, null, null);
                Assert.Fail("expected NotImplementedException");
            }
            catch (NotImplementedException)
            {
            }
        }
    }
}
